<template>
  <div style="padding: 30px; text-align: left">
      <a-row type="flex">
          <a-col flex="100px" @click="goBack"
            ><div style="text-align: left; cursor:pointer;"><a-icon type="arrow-left" /></div
          ></a-col>
          <a-col flex="auto">

          </a-col>
        </a-row>
    <a-tabs default-active-key="1">
      <a-tab-pane key="1">
        <span slot="tab">
          <!-- <a-icon type="apple" /> -->
          交易信息
        </span>
        <tx-info :transaction="transaction"></tx-info>
      </a-tab-pane>
      <a-tab-pane key="2">
        <span slot="tab">
          <!-- <a-icon type="android" /> -->
          交易收据
        </span>
        <tx-receipt :receipt="receipt">></tx-receipt>
      </a-tab-pane>
    </a-tabs>
  </div>
</template>

<script>
import Constant from "../utils/Constant";
import TxInfo from "../components/TxInfo";
import TxReceipt from "../components/TxReceipt.vue";

export default {
  components: {
    TxInfo,
    TxReceipt,
  },
  data() {
    return {
      transaction: {},
      receipt: {},
    };
  },
  created() {
    console.log("created");
    console.log(this.$route.query);
    if (this.$route.query.hash) {
      this.getTransaction(this.$route.query.hash);
      this.getReceipt(this.$route.query.hash);
    }
  },
  methods: {
    getTransaction(txHash) {
      let url = Constant.TX_HASH_URL + txHash;
      this.$http.get(url).then(
        (resp) => {
          console.log(resp);
          if (resp.data.code === "01") {
            this.transaction = resp.data.result;
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
    getReceipt(txHash) {
      let url = Constant.TX_RECEIPT_URL + txHash;
      this.$http.get(url).then(
        (resp) => {
          console.log(resp);
          if (resp.data.code === "01") {
            this.receipt = resp.data.result;
          } else {
            this.$message.error(resp.data.message)
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
    goBack() {
      console.log("go back");
      this.$router.go(-1);
    },

  },
};
</script>
